<!--#include file="p1.asp" -->
<%
dim action
action=val("action")
if action="numb" then
	numb	
elseif action="prj_c_save" then
	prj_c_save
elseif action="t_prj_save" then
	t_prj_save	
elseif action="c_prj_save" then
	c_prj_save
elseif action="qx_save" then
	qx_save
elseif action="dbinfo" then
	dbinfo
elseif action="inputlog" then
	inputlog
elseif action="emp2" then
	emp2
elseif action="exp_xls" then
	exp_xls
elseif action="c_list" then
	c_list
elseif action="qx_list" then
	qx_list	
end if

Function t_prj_list(tid)
	dim sql,rs1,cnt
	sql="select * from [prj] "
	Set rs1 = Easp.Db.Sel(sql)
	vas "tid",tid
	Do While Not rs1.EOF		
		vas "pid",rs1("ID")
		sql="select count(id) from prj_t where tid={tid:int} and pid={pid:int} "
		cnt = Easp.Db.Sel(sql)(0)
		if cnt = 0 then
			cb rs1("ID"),rs1("prn"),""
		else
			cb rs1("ID"),rs1("prn"),"checked"
		end if
		rs1.MoveNext
	Loop
End Function
Function c_prj_list(cid)
	dim sql,rs1,cnt
	sql="select * from [prj] "
	Set rs1 = Easp.Db.Sel(sql)
	vas "cid",cid
	Do While Not rs1.EOF		
		vas "pid",rs1("ID")
		sql="select count(id) from prj_c where cid={cid:int} and pid={pid:int} "
		cnt = Easp.Db.Sel(sql)(0)
		if cnt = 0 then
			cb rs1("ID"),rs1("prn"),""
		else
			cb rs1("ID"),rs1("prn"),"checked"
		end if
		rs1.MoveNext
	Loop
End Function

Function prj_c_list(pid)
	dim sql,rs1,cnt
	sql="select * from [center] "
	Set rs1 = Easp.Db.Sel(sql)
	vas "pid",pid
	Do While Not rs1.EOF		
		vas "cid",rs1("ID")
		sql="select count(id) from prj_c where cid={cid:int} and pid={pid:int} "
		cnt = Easp.Db.Sel(sql)(0)
		if cnt = 0 then
			cb rs1("ID"),rs1("cn"),""
		else
			cb rs1("ID"),rs1("cn"),"checked"
		end if
		rs1.MoveNext
	Loop
End Function
function prj_c_save()
	dim sql,rs1,ret
	sql="select * from [center]"
	Set rs1 = Easp.Db.Sel(sql)
	Easp.Db.del "prj_c","pid={pid}"
	Do While Not rs1.EOF		
		if val(hr_1(rs1("ID")))="on" then
			vas "cid",rs1("id")
			sql=cr("prj_c","pid,cid")
			ret = Easp.Db.Exec(sql)
		end if
		rs1.MoveNext
	Loop
	ret3(ret)
end function

function t_prj_save()
	dim sql,rs1,ret
	sql="select * from [prj]"
	Set rs1 = Easp.Db.Sel(sql)
	Easp.Db.del "prj_t","tid={tid}"
	Do While Not rs1.EOF		
		if val(hr_1(rs1("ID")))="on" then
			vas "pid",rs1("id")
			sql=cr("prj_t","pid,tid")
			ret = Easp.Db.Exec(sql)
		end if
		rs1.MoveNext
	Loop
	ret3(ret)
end function
function c_prj_save()
	dim sql,rs1,ret
	sql="select * from [prj]"
	Set rs1 = Easp.Db.Sel(sql)
	Easp.Db.del "prj_c","cid={cid}"
	Do While Not rs1.EOF		
		if val(hr_data(rs1("ID")))="on" then
			vas "pid",rs1("id")
			sql=cr("prj_c","pid,cid")
			ret = Easp.Db.Exec(sql)
		end if
		rs1.MoveNext
	Loop
	ret3(ret)
end function

function exp_xls()
	Response.Write "<a href='http://"  & Request.ServerVariables("HTTP_HOST") & "/dzps/file/xls/" & val("wlbm") & ".xls"  &"'>" & val("wlbm") & ".xls" &"</a>"
end function

function bianli()
        dim fso            'fso对象
        dim objFolder      '文件夹对象
        dim objSubFolders  '子文件夹集合
        dim objSubFolder   '子文件夹对象
        dim objFiles       '文件集合
        dim objFile        '文件对象
		dim path,nowpath
		path=Server.MapPath("\") & "\dzps\file\xls"
		' echo path
        set fso=server.CreateObject("scripting.filesystemobject")   
        set objFolder=fso.GetFolder(path)'创建文件夹对象
        set objSubFolders=objFolder.Subfolders'创建的子文件夹对象
        for each objSubFolder in objSubFolders
            nowpath=path + "\\" + objSubFolder.name
            ' Response.Write nowpath
            set objFiles=objSubFolder.Files
            for each objFile in objFiles
				echo objFile.name
				echo "aaaa"
				if instr(objFile.name,"xls")>0 then
								Response.Write "<br>---"
								Response.Write "<a href='"& "/dzps/file/xls/" & objFile.name   &"'>" &objFile.name&"</a>"
				end if            
			next
            Response.Write "<p>"
			' bianli(nowpath)    '调用递归
        next
        set objFolder=nothing
        set objSubFolders=nothing
        set fso=nothing
end function

sub emp2(tn)
	dim s,sql,filename,fs,myfile,x,strLine,rstData,strsql
	strSql="select * from " & tn
	Set fs = server.CreateObject("scripting.filesystemobject") 
	'--假设你想让生成的EXCEL文件做如下的存放 
	filename = Server.MapPath("./dbs/xls/"& tn&".xls") 
	'--如果原来的EXCEL文件存在的话删除它 
	if fs.FileExists(filename) then 
	   fs.DeleteFile(filename) 
	end  if 
	'--创建EXCEL文件 
	set myfile = fs.CreateTextFile(filename,true) 
	' strSql = "select * from 追风透骨胶囊治疗骨关节炎的上市后再评价0 "
	Set rstData =easp.db.select(Conn2,strSql)
	if not rstData.EOF and not rstData.BOF then 
	  
	   dim  trLine,responsestr 
	   strLine=""
	   For each x in rstData.fields 
		 strLine = strLine & x.name & chr(9) 
	   Next
	  
	'--将表的列名先写入EXCEL 
	   myfile.writeline strLine 
	  
	   Do while Not rstData.EOF 
		 strLine=""
	  
		 for each x in rstData.Fields 
		   strLine = strLine & x.value &  chr(9) 
		 next 
		 myfile.writeline  strLine 
	  
		 rstData.MoveNext 
	   loop 
	  
	end if 
	rstData.Close 
	set rstData = nothing
end sub

sub exp3()
	dim rs1,i,ret
	dim rsArray,sql
	set rs1 = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} order by tn")
	i=0
	Do While Not rs1.EOF		
		i=i+1
		emp2(rs1("tn"))
		rs1.MoveNext
	Loop
	ret3("1")
end sub
function dbinfo()
	dim sql,ret
	sql=xg("dbs","dbinfo","id={id}")
	ret = Easp.Db.Exec(sql)
	ret1(ret)
end function
function inputlog()
	dim sql
	sql="select * from [baseinfo3] where mode in ('inputlog','inputman') and dbName like '%{=dbName1}%' order by id desc"
	qry2json(sql)
end function
function qx_save()
	dim sql,rs1,ret
	vas "username",val("usernameqx")
	sql="select * from [dbs] where dbName like '%" &  easp.var("dbName1") & "%' order by id desc"
	Set rs1 = Easp.Db.Sel(sql)
	Easp.Db.del "t_qx","username={username}"
	Do While Not rs1.EOF		
		if val(hr_1(rs1("ID")))="on" then
			vas "t_db4qx_id",rs1("id")
			sql=cr("t_qx","username,t_db4qx_id,dbName")
			ret = Easp.Db.Exec(sql)
		end if
		rs1.MoveNext
	Loop
	ret3(ret)
end function
Function qx_list(usernameqx)
	dim sql,rs1,cnt
	vas "usernameqx",usernameqx
	sql="select * from [dbs] where (1=1) and dbName like '%" &  easp.var("dbName1") & "%' order by id desc"
	if val("username")<>"" then
		vas "likeKey" ,"%{=username}%"
		sql=replace(sql,"1=1","dbName like {likeKey}")
	end if	
	Set rs1 = Easp.Db.Sel(sql)
	Do While Not rs1.EOF		
		vas "id",rs1("ID")
		sql="select count(id) from t_qx where username={usernameqx} and t_db4qx_id={id}"
		cnt = Easp.Db.Sel(sql)(0)
		if cnt = 0 then
			cb rs1("ID"),rs1("dbName"),""
		else
			cb rs1("ID"),rs1("dbName"),"checked"
		end if
		rs1.MoveNext
	Loop
End Function



Function numb()
	dim sql,ret,cnt
	sql=cr(val("table_name") ,"numb")
	cnt = Easp.Db.Select(conn2, "select count(numb) as cnt from {=table_name} where numb={numb}")(0)
	if cnt=0 then
		ret = Easp.Db.Execute(conn2, sql)
		conci2()
		henji2(val("numb"))
		ret1(ret)
	else
		ret3("NUMB："& val("numb") &"已存在")
	end if
End Function


function henji2(numb)
	dim sql
	vas "numb",numb
	vas "f1",session("username")
	vas "mode","inputman"
	Easp.Db.Del "baseinfo3","dbName={dbName} and table_name={table_name} and numb={numb} and mode={mode}"
	sql = cr("baseinfo3","dbName,table_name,numb,f1,mode")
	Easp.Db.Exec(sql)
end function

sub conci2()
	dim rs1,tablename,sql,rs2,arr,i,txt
	txt=" and tn in (" & sextable & ")"

	tablename = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} " & txt & " order by tn")("tn")
	vas "tablename",tablename
    
	set rs1 = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} "& txt & " order by tn")
	set rs2 = Easp.Db.Select(conn2, "select numb from {=tablename}")
	if rs2.recordCount >=1 then
		arr = rs2.GetRows
		Do While Not rs1.EOF		
			if extable(rs1("tn"))=1 then 
				vas "tablename",rs1("tn")
				for i=0 to ubound(arr,2)
					vas "numb",arr(0,i)
					Set rs2 = Easp.Db.Execute(conn2, "Select count(*) From {=tablename} where numb = {numb}")		
					if rs2(0) = 0 then
						sql= cr(val("tablename"),"numb")
						rs2 = Easp.Db.Execute(conn2, sql)					
					end if
				next 
			end if
			rs1.MoveNext
		Loop		
	else
	end if
	Easp.Db.Close rs1
	Easp.Db.Close rs2
end sub
%>
